﻿<!DOCTYPE html>
<html>
<head>
    <title>Studio Images</title>
</head>
<body>
    <div id="configPage" data-role="page" class="page type-interior pluginConfigurationPage configPage" data-require="emby-input,emby-button,emby-checkbox">
        <div data-role="content">
            <div class="content-primary">
                <h1>Studio Images</h1>
                <form class="configForm">
                    <div class="inputContainer">
                        <input is="emby-input" type="text" id="repository" label="Repository" />
                        <div class="fieldDescription">This can be any Jellyfin-compatible artwork repository. Leave blank to use default repository.</div>
                    </div>
                    <br />
                    <div>
                        <button is="emby-button" type="submit" class="raised button-submit block"><span>Save</span></button>
                    </div>
                </form>
            </div>
        </div>
        <script type="text/javascript">
            var PluginConfig = {
                pluginId: "872a7849-1171-458d-a6fb-3de3d442ad30"
            };

            document.querySelector('.configPage')
                .addEventListener('pageshow', function () {
                    Dashboard.showLoadingMsg();
                    ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) {
                        var repository = document.querySelector('#repository');
                        repository.value = config.RepositoryUrl;
                        repository.dispatchEvent(new Event('change', {
                            bubbles: true,
                            cancelable: false
                        }));

                        Dashboard.hideLoadingMsg();
                    });
                });

            document.querySelector('.configForm')
                .addEventListener('submit', function (e) {
                    Dashboard.showLoadingMsg();

                    ApiClient.getPluginConfiguration(PluginConfig.pluginId).then(function (config) {
                        config.RepositoryUrl = document.querySelector('#repository').value;

                        ApiClient.updatePluginConfiguration(PluginConfig.pluginId, config).then(Dashboard.processPluginConfigurationUpdateResult);
                    });

                    e.preventDefault();
                    return false;
                });
        </script>
    </div>
</body>
</html>
